package com.spareparts.activity;

import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.spareparts.R;

@SuppressWarnings("deprecation")
public class SparePartsActivity extends ActivityGroup 
{
	private TextView mSearchTextView;
	private TextView mInventoryTextView;
	private TextView mInventoryChangeTextView;
	private TextView mBorrowTextView;
	private TextView mRepairTextView;
	
	private final int SEARCH_CLICK = 0;
	private final int INVENTORY_CLICK = 1;
	private final int INVENTORY_CHANGE_CLICK = 2;
	private final int BORROW_CLICK = 3;
	private final int REPAIR_CLICK = 4;
	
	private LinearLayout mContainer;
	private LocalActivityManager manager;
	private Context mContext;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_spare);
		mContext = this;
		
		mSearchTextView = (TextView) findViewById(R.id.buttonSearch);
		mInventoryTextView = (TextView) findViewById(R.id.buttonInventory);
		mInventoryChangeTextView = (TextView) findViewById(R.id.buttonInventoryChange);
		mBorrowTextView = (TextView) findViewById(R.id.buttonBorrow);
		mRepairTextView = (TextView) findViewById(R.id.buttonRepair);
		mContainer = (LinearLayout) findViewById(R.id.container);
		
		manager=getLocalActivityManager();
		
		
		setTextViewOnClick();
		
		setIntent(SEARCH_CLICK);
	}
	
	/**
	 * 设置单击事件
	 */
	private void setTextViewOnClick()
	{
		mSearchTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(SEARCH_CLICK);
			}
		});
		
		mInventoryTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(INVENTORY_CLICK);
			}
		});
		
		mInventoryChangeTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(INVENTORY_CHANGE_CLICK);
			}
		});
		
		mBorrowTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(BORROW_CLICK);
			}
		});
		
		mRepairTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(REPAIR_CLICK);
			}
		});
	}
	
	/**
	 * 设置跳转事件
	 */
	private void setIntent(int num)
	{
		 //TODO 点击前所有的textview的状态
		
		
		 //设置跳转
		 if(num == SEARCH_CLICK)
		 {
			 mContainer.removeAllViews();
			 mContainer.addView(manager.startActivity(
						"PAGE_0",
						new Intent(mContext, SparePartsSearchActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
						.getDecorView());
		 }
		 else if(num == INVENTORY_CLICK)
		 {
			 
		 }
		 else if(num == INVENTORY_CHANGE_CLICK)
		 {
			 
		 }
		 else if(num == BORROW_CLICK)
		 {
			 
		 }
		 else if(num == REPAIR_CLICK)
		 {
			 
		 }
	}
}
